if (window.console === undefined) 
{
	window.isStorageLogs = true;
	window.isCreateNopConsole = true;
	console = {
		start_time:new Date(),
		logs_storage:[],
		log : function(msg) {
			if (window.isStorageLogs==true)
			{
				this.logs_storage.push({dt:new Date(),t:0,msg:msg});
			}
		},
		error : function(msg) {
			alert(msg);
			if (window.isStorageLogs==true)
			{
				this.logs_storage.push({dt:new Date(),t:1,msg:msg});
			}
		}
	};
};

$(document).ready( function initLog() {
	if (window.console === undefined || window.isCreateNopConsole == true) {
		var log = $('<div id="log-system" class="log"/>').css( {
			color :"000000",
			zIndex :"999999",
			position :"absolute",
			top:"0px",
			left:"0px",
			overflow:"auto",
			height:"300px",
			width:"100%",
			border:"1px solid",
			background:"white"
		}).hide().appendTo(document.body);
		var start_date = window.console.start_time.getTime();
		
		function datetimeFormat(date)
		{
			var nms = date.getTime()-start_date;
			var ms = parseInt(nms % 1000);
			var sec = ((nms-ms)/1000).toFixed(0);
			return "["+sec+":"+ms.toPrecision(3)+"] ";
		}
		
		function addLog(time,text)
		{
			$('<div class="log-item-log"/>').text(time+text).appendTo(log);
		}
		function addError(time,text)
		{
			$('<div class="log-item-error"/>').text(time+text).appendTo(log);
		}
		
		var list = window.console.logs_storage;
		for(var i = 0 ; i<list.length ; i++)
		{
			var item = list[i];
			if (item.t==0)
			{
				addLog(datetimeFormat(item.dt),item.msg);
			}else
			{
				addError(datetimeFormat(item.dt),item.msg);
			}
		}
		
		console = {
			log : function(text) {
				addLog(datetimeFormat(new Date()),text);
			},
			error : function(text) {
				addError(datetimeFormat(new Date()),text);
			}
		};
	};
	$(document).keyup( function(event) {
		if (event.keyCode == 27) {
			var obj = $('#log-system');
			if (obj.attr('show') == "1") {
				obj.hide().attr('show', 0);
			} else {
				obj.show().attr('show', 1);
			}
		}
	});
});

console.log("load:log.js");